# coding=gbk
"""
Created on 2016/6/15 0015

@author: Blunce

@about:

"""
import numpy as np
import os

ANNOTATIONS_DES = [
    "Normal_beat",
    "Left_bundle_branch_block_beat",
    "Right_bundle_branch_block_beat",
    "Premature_ventricular_contraction",
    "Paced_beat",
    "Atrial_premature_beat",
    "Fusion_of_paced_and_normal_beat",
    "Fusion_of_ventricular_and_normal_beat",
    "Ventricular_flutter_wave",
    "Aberrated_atrial_premature_beat"
]


def save_as_csv(data, filename):
    with open(filename, "w") as fw:
        for line in data:
            x = ""
            for i in range(len(line)):
                x += str(line[i]) + ','
            fw.write(x[:-1] + '\n')


def read_csv(filename, type=float):
    with open(filename) as fr:
        lines = fr.readlines()
        data = []
        for line in lines:
            data.append(np.array(line.strip('\n').split(","), dtype=type))
        return data


def pickle_read(path_file):
    import pickle
    with open(path_file, "rb") as fp:
        return pickle.load(fp)


def pickle_save(path_file, data):
    import pickle
    with open(path_file, "wb") as fp:
        pickle.dump(data, fp)


if __name__ == '__main__':
    print "**************start**************\n\n"

    x = np.arange(10)
    path_file = os.getcwd()[:-5] + "data" + os.sep + "test" + os.sep + "test.x"
    pickle_save(path_file, x)
    print pickle_read(path_file)

    print "\n\n**************end**************"
